cmake_minimum_required(VERSION 3.22)
project(scepter_lerobot_driver)

# Default to C++17
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 17)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# Find dependencies
find_package(ament_cmake REQUIRED)
find_package(ament_cmake_python REQUIRED)
find_package(hardware_interface REQUIRED)
find_package(pluginlib REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
find_package(pybind11_vendor REQUIRED)
find_package(pybind11 REQUIRED)

# Create hardware interface library
add_library(
  scepter_lerobot_driver_plugin
  SHARED
  src/lerobot_hardware_interface.cpp
)

target_include_directories(
  scepter_lerobot_driver_plugin
  PRIVATE
  include
)

ament_target_dependencies(
  scepter_lerobot_driver_plugin
  hardware_interface
  pluginlib
  rclcpp
  rclcpp_lifecycle
)

# Install the library
install(
  TARGETS scepter_lerobot_driver_plugin
  DESTINATION lib
)

# Install plugin description
install(
  FILES pluginlib_export_scepter_lerobot_driver.xml
  DESTINATION share/${PROJECT_NAME}
)

# Install Python modules
ament_python_install_package(${PROJECT_NAME})

# Install Python scripts
install(PROGRAMS
  scripts/lerobot_bridge_node.py
  DESTINATION lib/${PROJECT_NAME}
)

# Install config files
install(DIRECTORY 
  config
  DESTINATION share/${PROJECT_NAME}
)

# Install launch files
install(DIRECTORY
  launch
  DESTINATION share/${PROJECT_NAME}
)

# Export dependencies
ament_export_targets(scepter_lerobot_driver_plugin HAS_LIBRARY_TARGET)
ament_export_dependencies(
  hardware_interface
  pluginlib
  rclcpp
  rclcpp_lifecycle
)

ament_package()